From 00cbf8bcca9d047eead535ebd5bc986365b04426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:24:53 +0100 Subject: tap: clang-format diff --git a/tap/tap.c b/tap/tap.c index 97c20e9..00ceab2 100644 --- a/tap/tap.c +++ b/tap/tap.c @@ -35,8 +35,8 @@ static int no_plan = 0; static int skip_all = 0; static int have_plan = 0; static unsigned int test_count = 0; /* Number of tests that have been run */ -static unsigned int e_tests = 0; /* Expected number of tests to run */ -static unsigned int failures = 0; /* Number of tests that failed */ +static unsigned int e_tests = 0; /* Expected number of tests to run */ +static unsigned int failures = 0; /* Number of tests that failed */ static char *todo_msg = NULL; static char *todo_msg_fixed = "libtap malloc issue"; static int todo = 0; @@ -45,13 +45,13 @@ static int test_died = 0; /* Encapsulate the pthread code in a conditional. In the absence of libpthread the code does nothing */ #ifdef HAVE_LIBPTHREAD -#include +# include static pthread_mutex_t M = PTHREAD_MUTEX_INITIALIZER; -# define LOCK pthread_mutex_lock(&M); -# define UNLOCK pthread_mutex_unlock(&M); +# define LOCK pthread_mutex_lock(&M); +# define UNLOCK pthread_mutex_unlock(&M); #else -# define LOCK -# define UNLOCK +# define LOCK +# define UNLOCK #endif static void _expected_tests(unsigned int); @@ -65,10 +65,7 @@ static void _cleanup(void); * test_name -- the name of the test, may be NULL * test_comment -- a comment to print afterwards, may be NULL */ -unsigned int -_gen_result(int ok, const char *func, char *file, unsigned int line, - char *test_name, ...) -{ +unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line, char *test_name, ...) { va_list ap; char *local_test_name = NULL; char *c; @@ -80,7 +77,7 @@ _gen_result(int ok, const char *func, char *file, unsigned int line, /* Start by taking the test name and performing any printf() expansions on it */ - if(test_name != NULL) { + if (test_name != NULL) { va_start(ap, test_name); vasprintf(&local_test_name, test_name, ap); va_end(ap); @@ -88,43 +85,43 @@ _gen_result(int ok, const char *func, char *file, unsigned int line, /* Make sure the test name contains more than digits and spaces. Emit an error message and exit if it does */ - if(local_test_name) { + if (local_test_name) { name_is_digits = 1; - for(c = local_test_name; *c != '\0'; c++) { - if(!isdigit(*c) && !isspace(*c)) { + for (c = local_test_name; *c != '\0'; c++) { + if (!isdigit(*c) && !isspace(*c)) { name_is_digits = 0; break; } } - if(name_is_digits) { + if (name_is_digits) { diag(" You named your test '%s'. You shouldn't use numbers for your test names.", local_test_name); diag(" Very confusing."); } } } - if(!ok) { + if (!ok) { printf("not "); failures++; } printf("ok %d", test_count); - if(test_name != NULL) { + if (test_name != NULL) { printf(" - "); /* Print the test name, escaping any '#' characters it might contain */ - if(local_test_name != NULL) { + if (local_test_name != NULL) { flockfile(stdout); - for(c = local_test_name; *c != '\0'; c++) { - if(*c == '#') + for (c = local_test_name; *c != '\0'; c++) { + if (*c == '#') fputc('\\', stdout); fputc((int)*c, stdout); } funlockfile(stdout); - } else { /* vasprintf() failed, use a fixed message */ + } else { /* vasprintf() failed, use a fixed message */ printf("%s", todo_msg_fixed); } } @@ -136,17 +133,16 @@ _gen_result(int ok, const char *func, char *file, unsigned int line, This is not counted as a failure, so decrement the counter if the test failed. */ - if(todo) { + if (todo) { printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed); - if(!ok) + if (!ok) failures--; } printf("\n"); - if(!ok) - diag(" Failed %stest (%s:%s() at line %d)", - todo ? "(TODO) " : "", file, func, line); + if (!ok) + diag(" Failed %stest (%s:%s() at line %d)", todo ? "(TODO) " : "", file, func, line); free(local_test_name); @@ -161,18 +157,16 @@ _gen_result(int ok, const char *func, char *file, unsigned int line, * Initialise the TAP library. Will only do so once, however many times it's * called. */ -void -_tap_init(void) -{ +void _tap_init(void) { static int run_once = 0; LOCK; - if(!run_once) { + if (!run_once) { atexit(_cleanup); /* stdout needs to be unbuffered so that the output appears - in the same place relative to stderr output as it does + in the same place relative to stderr output as it does with Test::Harness */ setbuf(stdout, 0); run_once = 1; @@ -184,15 +178,13 @@ _tap_init(void) /* * Note that there's no plan. */ -int -plan_no_plan(void) -{ +int plan_no_plan(void) { LOCK; _tap_init(); - if(have_plan != 0) { + if (have_plan != 0) { fprintf(stderr, "You tried to plan twice!\n"); test_died = 1; UNLOCK; @@ -210,9 +202,7 @@ plan_no_plan(void) /* * Note that the plan is to skip all tests */ -int -plan_skip_all(char *reason) -{ +int plan_skip_all(char *reason) { LOCK; @@ -222,7 +212,7 @@ plan_skip_all(char *reason) printf("1..0"); - if(reason != NULL) + if (reason != NULL) printf(" # Skip %s", reason); printf("\n"); @@ -235,22 +225,20 @@ plan_skip_all(char *reason) /* * Note the number of tests that will be run. */ -int -plan_tests(unsigned int tests) -{ +int plan_tests(unsigned int tests) { LOCK; _tap_init(); - if(have_plan != 0) { + if (have_plan != 0) { fprintf(stderr, "You tried to plan twice!\n"); test_died = 1; UNLOCK; exit(255); } - if(tests == 0) { + if (tests == 0) { fprintf(stderr, "You said to run 0 tests! You've got to run something.\n"); test_died = 1; UNLOCK; @@ -266,9 +254,7 @@ plan_tests(unsigned int tests) return 0; } -unsigned int -diag(char *fmt, ...) -{ +unsigned int diag(char *fmt, ...) { va_list ap; LOCK; @@ -286,9 +272,7 @@ diag(char *fmt, ...) return 0; } -void -_expected_tests(unsigned int tests) -{ +void _expected_tests(unsigned int tests) { LOCK; @@ -298,9 +282,7 @@ _expected_tests(unsigned int tests) UNLOCK; } -int -skip(unsigned int n, char *fmt, ...) -{ +int skip(unsigned int n, char *fmt, ...) { va_list ap; char *skip_msg; @@ -310,11 +292,9 @@ skip(unsigned int n, char *fmt, ...) asprintf(&skip_msg, fmt, ap); va_end(ap); - while(n-- > 0) { + while (n-- > 0) { test_count++; - printf("ok %d # skip %s\n", test_count, - skip_msg != NULL ? - skip_msg : "libtap():malloc() failed"); + printf("ok %d # skip %s\n", test_count, skip_msg != NULL ? skip_msg : "libtap():malloc() failed"); } free(skip_msg); @@ -324,9 +304,7 @@ skip(unsigned int n, char *fmt, ...) return 1; } -void -todo_start(char *fmt, ...) -{ +void todo_start(char *fmt, ...) { va_list ap; LOCK; @@ -340,9 +318,7 @@ todo_start(char *fmt, ...) UNLOCK; } -void -todo_end(void) -{ +void todo_end(void) { LOCK; @@ -352,28 +328,26 @@ todo_end(void) UNLOCK; } -int -exit_status(void) -{ +int exit_status(void) { int r; LOCK; /* If there's no plan, just return the number of failures */ - if(no_plan || !have_plan) { + if (no_plan || !have_plan) { UNLOCK; return failures; } /* Ran too many tests? Return the number of tests that were run that shouldn't have been */ - if(e_tests < test_count) { + if (e_tests < test_count) { r = test_count - e_tests; UNLOCK; return r; } - /* Return the number of tests that failed + the number of tests + /* Return the number of tests that failed + the number of tests that weren't run */ r = failures + e_tests - test_count; UNLOCK; @@ -385,51 +359,45 @@ exit_status(void) * Cleanup at the end of the run, produce any final output that might be * required. */ -void -_cleanup(void) -{ +void _cleanup(void) { LOCK; /* If plan_no_plan() wasn't called, and we don't have a plan, and we're not skipping everything, then something happened before we could produce any output */ - if(!no_plan && !have_plan && !skip_all) { + if (!no_plan && !have_plan && !skip_all) { diag("Looks like your test died before it could output anything."); UNLOCK; return; } - if(test_died) { + if (test_died) { diag("Looks like your test died just after %d.", test_count); UNLOCK; return; } - /* No plan provided, but now we know how many tests were run, and can print the header at the end */ - if(!skip_all && (no_plan || !have_plan)) { + if (!skip_all && (no_plan || !have_plan)) { printf("1..%d\n", test_count); } - if((have_plan && !no_plan) && e_tests < test_count) { - diag("Looks like you planned %d tests but ran %d extra.", - e_tests, test_count - e_tests); + if ((have_plan && !no_plan) && e_tests < test_count) { + diag("Looks like you planned %d tests but ran %d extra.", e_tests, test_count - e_tests); UNLOCK; return; } - if((have_plan || !no_plan) && e_tests > test_count) { - diag("Looks like you planned %d tests but only ran %d.", - e_tests, test_count); + if ((have_plan || !no_plan) && e_tests > test_count) { + diag("Looks like you planned %d tests but only ran %d.", e_tests, test_count); UNLOCK; return; } - if(failures) - diag("Looks like you failed %d tests of %d.", - failures, test_count); + if (failures) + diag("Looks like you failed %d tests of %d.", failures, test_count); UNLOCK; } diff --git a/tap/tap.h b/tap/tap.h index 8ee525c..5abbd76 100644 --- a/tap/tap.h +++ b/tap/tap.h @@ -28,52 +28,46 @@ and requires the caller to add the final comma if they've omitted the optional arguments */ #ifdef __GNUC__ -# define ok(e, test, ...) ((e) ? \ - _gen_result(1, __func__, __FILE__, __LINE__, \ - test, ## __VA_ARGS__) : \ - _gen_result(0, __func__, __FILE__, __LINE__, \ - test, ## __VA_ARGS__)) +# define ok(e, test, ...) \ + ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__) \ + : _gen_result(0, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__)) -# define ok1(e) ((e) ? \ - _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \ - _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) +# define ok1(e) ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) -# define pass(test, ...) ok(1, test, ## __VA_ARGS__); -# define fail(test, ...) ok(0, test, ## __VA_ARGS__); +# define pass(test, ...) ok(1, test, ##__VA_ARGS__); +# define fail(test, ...) ok(0, test, ##__VA_ARGS__); -# define skip_start(test, n, fmt, ...) \ - do { \ - if((test)) { \ - skip(n, fmt, ## __VA_ARGS__); \ - continue; \ - } +# define skip_start(test, n, fmt, ...) \ + do { \ + if ((test)) { \ + skip(n, fmt, ##__VA_ARGS__); \ + continue; \ + } #else /* __GNUC__ */ /* The original tap.h used to test if __STDC_VERSION__ >= 199901L here. This * doesn't seem to work on HP-UX even though the code compile fine. I'm not * sure how to add an exception here for HP-UX so I just removed the check * for now */ -# define ok(e, ...) ((e) ? \ - _gen_result(1, __func__, __FILE__, __LINE__, \ - __VA_ARGS__) : \ - _gen_result(0, __func__, __FILE__, __LINE__, \ - __VA_ARGS__)) +# define ok(e, ...) \ + ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, __VA_ARGS__) : _gen_result(0, __func__, __FILE__, __LINE__, __VA_ARGS__)) -# define ok1(e) ((e) ? \ - _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \ - _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) +# define ok1(e) ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) -# define pass(...) ok(1, __VA_ARGS__); -# define fail(...) ok(0, __VA_ARGS__); +# define pass(...) ok(1, __VA_ARGS__); +# define fail(...) ok(0, __VA_ARGS__); -# define skip_start(test, n, ...) \ - do { \ - if((test)) { \ - skip(n, __VA_ARGS__); \ - continue; \ - } +# define skip_start(test, n, ...) \ + do { \ + if ((test)) { \ + skip(n, __VA_ARGS__); \ + continue; \ + } #endif /* __GNUC__ */ -# define skip_end } while(0); +#define skip_end \ + } \ + while (0) \ + ; unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...); diff --git a/tap/tests/diag/test.c b/tap/tests/diag/test.c index 401db64..b0a5a4f 100644 --- a/tap/tests/diag/test.c +++ b/tap/tests/diag/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; plan_tests(2); diff --git a/tap/tests/fail/test.c b/tap/tests/fail/test.c index 621b6c2..18e1695 100644 --- a/tap/tests/fail/test.c +++ b/tap/tests/fail/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(2); diff --git a/tap/tests/ok/ok-hash/test.c b/tap/tests/ok/ok-hash/test.c index 16be137..82f65b0 100644 --- a/tap/tests/ok/ok-hash/test.c +++ b/tap/tests/ok/ok-hash/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(4); @@ -42,11 +40,11 @@ main(int argc, char *argv[]) rc = ok(1, "Test with one # hash"); diag("Returned: %d", rc); - rc = ok(1, "Test with # two # hashes"); + rc = ok(1, "Test with # two # hashes"); diag("Returned: %d", rc); rc = ok(1, "Test with ## back to back hashes"); diag("Returned: %d", rc); - + return exit_status(); } diff --git a/tap/tests/ok/ok-numeric/test.c b/tap/tests/ok/ok-numeric/test.c index 0e33a74..46113f4 100644 --- a/tap/tests/ok/ok-numeric/test.c +++ b/tap/tests/ok/ok-numeric/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(3); diff --git a/tap/tests/ok/ok/test.c b/tap/tests/ok/ok/test.c index ae04f2e..8ef0bcd 100644 --- a/tap/tests/ok/ok/test.c +++ b/tap/tests/ok/ok/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(5); diff --git a/tap/tests/pass/test.c b/tap/tests/pass/test.c index 39d8a7c..73df20c 100644 --- a/tap/tests/pass/test.c +++ b/tap/tests/pass/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(2); diff --git a/tap/tests/plan/no-tests/test.c b/tap/tests/plan/no-tests/test.c index 78c5d37..f70ec8d 100644 --- a/tap/tests/plan/no-tests/test.c +++ b/tap/tests/plan/no-tests/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(0); diff --git a/tap/tests/plan/no_plan/test.c b/tap/tests/plan/no_plan/test.c index 5cffbdc..4c25d5f 100644 --- a/tap/tests/plan/no_plan/test.c +++ b/tap/tests/plan/no_plan/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_no_plan(); diff --git a/tap/tests/plan/not-enough-tests/test.c b/tap/tests/plan/not-enough-tests/test.c index a9ec64f..eacc07e 100644 --- a/tap/tests/plan/not-enough-tests/test.c +++ b/tap/tests/plan/not-enough-tests/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(1); diff --git a/tap/tests/plan/sane/test.c b/tap/tests/plan/sane/test.c index 0843d3a..17bf8d1 100644 --- a/tap/tests/plan/sane/test.c +++ b/tap/tests/plan/sane/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(1); diff --git a/tap/tests/plan/skip_all/test.c b/tap/tests/plan/skip_all/test.c index 31722da..4e37e1a 100644 --- a/tap/tests/plan/skip_all/test.c +++ b/tap/tests/plan/skip_all/test.c @@ -26,9 +26,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_skip_all("No good reason"); diff --git a/tap/tests/plan/too-many-plans/test.c b/tap/tests/plan/too-many-plans/test.c index b189cb7..5f45bc4 100644 --- a/tap/tests/plan/too-many-plans/test.c +++ b/tap/tests/plan/too-many-plans/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(1); diff --git a/tap/tests/plan/too-many-tests/test.c b/tap/tests/plan/too-many-tests/test.c index 0f72410..0b2ee16 100644 --- a/tap/tests/plan/too-many-tests/test.c +++ b/tap/tests/plan/too-many-tests/test.c @@ -28,9 +28,7 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; rc = plan_tests(5); diff --git a/tap/tests/skip/test.c b/tap/tests/skip/test.c index d8f3eaf..789812e 100644 --- a/tap/tests/skip/test.c +++ b/tap/tests/skip/test.c @@ -28,29 +28,27 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; unsigned int side_effect = 0; rc = plan_tests(4); diag("Returned: %d", rc); - rc = ok(1 == 1, "1 equals 1"); /* Should always work */ + rc = ok(1 == 1, "1 equals 1"); /* Should always work */ diag("Returned: %d", rc); do { - if(1) { + if (1) { rc = skip(1, "Testing skipping"); continue; } - + side_effect++; ok(side_effect == 1, "side_effect checked out"); - } while(0); + } while (0); diag("Returned: %d", rc); diff --git a/tap/tests/todo/test.c b/tap/tests/todo/test.c index ac6339a..0cd2fb3 100644 --- a/tap/tests/todo/test.c +++ b/tap/tests/todo/test.c @@ -28,16 +28,14 @@ #include "tap.h" -int -main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned int rc = 0; unsigned int side_effect = 0; rc = plan_tests(5); diag("Returned: %d", rc); - rc = ok(1 == 1, "1 equals 1"); /* Should always work */ + rc = ok(1 == 1, "1 equals 1"); /* Should always work */ diag("Returned: %d", rc); todo_start("For testing purposes"); -- cgit v0.10-9-g596f